<template>
  <div class="main">
    <div class="header">
      当前已设网点：
      <span class="blue">{{ initData.ssmName || '暂未设置网点' }}</span>
      <span class="input-info">* 不选中列表网点数据直接点确认，则为取消绑定当前网点</span>
    </div>
    <c-table
      ref="cTable"
      selection
      hasBorder
      :size="size"
      :max-height="448"
      :loading="isLoading"
      :table-header="tableHeader"
      :table-list="tableList"
      :page-info="pageInfo"
      :table-inner-btns="tableInnerBtns"
      @change-pagination="changePagination"
      @single-handle="changeSingleHandle"
    >
      <template v-slot:header>
        <c-search :form-model="searchObj" :form-items="searchItems" @submit-form="searchSubmit" @reset-form="searchReset"></c-search>
      </template>
    </c-table>
  </div>
</template>

<script>
import mixinTable from 'mixins/table'
// import utils from 'utils'
import { ssmQuerySsmApi } from '@/api/ssmApi'

export default {
  mixins: [mixinTable],
  props: {
    initData: {
      type: Object,
      default() {
        return []
      }
    }
  },
  data(vm) {
    return {
      ssmInfo: '',
      tableList: [],
      tableInnerBtns: [],
      tableHeader: [
        {
          label: '网点名称',
          prop: 'name',
          fixed: true,
          search: {
            type: 'input',
            prop: 'name'
          },
          width: 150
        },
        {
          label: '状态',
          prop: 'status',
          width: 100,
          setColor: row => (row.status == 0 ? 'red' : ''),
          formatter: row => row && vm.setTableColumnLabel(row.status, 'ssmStatusList')
          // search: {
          //   type: 'dict',
          //   optionsList: dictObj.disabledStatus
          // }
        },
        {
          label: '营业时间',
          prop: 'workTime',
          width: 100
        },
        {
          label: '联系电话',
          prop: 'tel',
          width: 120
        },
        {
          label: '用户评分',
          prop: 'userScore',
          width: 100
        },
        {
          label: '用户评级星数',
          prop: 'userGrade',
          width: 120
        },
        {
          label: '用户已评论总数',
          prop: 'userReviewCount',
          width: 120
        },
        {
          label: '订单量',
          prop: 'orderCount',
          width: 100
        },
        {
          label: '城市编码',
          prop: 'cityCode',
          width: 100
        },
        {
          label: '详细地址',
          prop: 'address',
          width: 150
        }
      ]
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      console.log('120===', this.searchObj)
      const { pageNo, pageSize } = this.pageInfo
      const { name } = this.searchObj
      this.isLoading = true
      ssmQuerySsmApi({
        pageSize,
        pageNo,
        name
      }).then(res => {
        this.isLoading = false
        if (res.code === 0) {
          console.log('217===', res)
          this.tableList = res.data.data
          this.pageInfo.totalNum = res.totalCount
        }
      })
    },
    changeSingleHandle(item) {
      this.ssmInfo = item
    }
  }
}
</script>
<style lang="less" scoped>
.main {
  .header {
    margin-bottom: 20px;
    font-size: 16px;
  }
}
</style>
